| Conditions | 1 |
| Paths | 1 |
| Total Lines | 124 |
| Lines | 124 |
| Ratio | 100 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* eslint-enable describe it sinon */ |
||
| 10 | it('Should turn a tree into a flat list with no identifier', () => { |
||
| 11 | |||
| 12 | const data = { |
||
| 13 | root: { |
||
| 14 | id: -1, |
||
| 15 | children: [ |
||
| 16 | { |
||
| 17 | id: 1, |
||
| 18 | parentId: -1, |
||
| 19 | children: [ |
||
| 20 | { |
||
| 21 | id: 11, |
||
| 22 | parentId: 1 |
||
| 23 | }, |
||
| 24 | { |
||
| 25 | id: 12, |
||
| 26 | parentId: 1, |
||
| 27 | children: [ |
||
| 28 | { |
||
| 29 | id: 121, |
||
| 30 | parentId: 12, |
||
| 31 | children: [ |
||
| 32 | { |
||
| 33 | id: 1211, |
||
| 34 | parentId: 121 |
||
| 35 | } |
||
| 36 | ] |
||
| 37 | } |
||
| 38 | ] |
||
| 39 | } |
||
| 40 | ] |
||
| 41 | }, |
||
| 42 | { |
||
| 43 | id: 2, |
||
| 44 | parentId: -1, |
||
| 45 | children: [ |
||
| 46 | { |
||
| 47 | id: 21, |
||
| 48 | parentId: 2 |
||
| 49 | } |
||
| 50 | ] |
||
| 51 | } |
||
| 52 | ] |
||
| 53 | } |
||
| 54 | }; |
||
| 55 | |||
| 56 | expect( |
||
| 57 | treeToFlatList(data) |
||
| 58 | ).toEqual([ |
||
| 59 | { |
||
| 60 | _id: -1, |
||
| 61 | _parentId: 'root', |
||
| 62 | _depth: 0, |
||
| 63 | _leaf: false, |
||
| 64 | _hideChildren: undefined, |
||
| 65 | _hasChildren: true, |
||
| 66 | _isExpanded: true |
||
| 67 | }, |
||
| 68 | { |
||
| 69 | _id: 1, |
||
| 70 | _parentId: -1, |
||
| 71 | _depth: 1, |
||
| 72 | _leaf: false, |
||
| 73 | _hideChildren: undefined, |
||
| 74 | _hasChildren: true, |
||
| 75 | _isExpanded: true |
||
| 76 | }, |
||
| 77 | { |
||
| 78 | _id: 11, |
||
| 79 | _parentId: 1, |
||
| 80 | _depth: 2, |
||
| 81 | _leaf: true, |
||
| 82 | _hideChildren: undefined, |
||
| 83 | _hasChildren: undefined, |
||
| 84 | _isExpanded: undefined |
||
| 85 | }, |
||
| 86 | { |
||
| 87 | _id: 12, |
||
| 88 | _parentId: 1, |
||
| 89 | _depth: 2, |
||
| 90 | _leaf: false, |
||
| 91 | _hideChildren: undefined, |
||
| 92 | _hasChildren: true, |
||
| 93 | _isExpanded: true |
||
| 94 | }, |
||
| 95 | { |
||
| 96 | _id: 121, |
||
| 97 | _parentId: 12, |
||
| 98 | _depth: 3, |
||
| 99 | _leaf: false, |
||
| 100 | _hideChildren: undefined, |
||
| 101 | _hasChildren: true, |
||
| 102 | _isExpanded: true |
||
| 103 | }, |
||
| 104 | { |
||
| 105 | _id: 1211, |
||
| 106 | _parentId: 121, |
||
| 107 | _depth: 4, |
||
| 108 | _leaf: true, |
||
| 109 | _hideChildren: undefined, |
||
| 110 | _hasChildren: undefined, |
||
| 111 | _isExpanded: undefined |
||
| 112 | }, |
||
| 113 | { |
||
| 114 | _id: 2, |
||
| 115 | _parentId: -1, |
||
| 116 | _depth: 1, |
||
| 117 | _leaf: false, |
||
| 118 | _hideChildren: undefined, |
||
| 119 | _hasChildren: true, |
||
| 120 | _isExpanded: true |
||
| 121 | }, |
||
| 122 | { |
||
| 123 | _id: 21, |
||
| 124 | _parentId: 2, |
||
| 125 | _depth: 2, |
||
| 126 | _leaf: true, |
||
| 127 | _hideChildren: undefined, |
||
| 128 | _hasChildren: undefined, |
||
| 129 | _isExpanded: undefined |
||
| 130 | } |
||
| 131 | ]); |
||
| 132 | |||
| 133 | }); |
||
| 134 | |||
| 390 |